#include<stdio.h>//Insertsort Shellsort
void Arrprint(int* arr, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}
void Insertsort(int* arr, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i;
		int tem = arr[end + 1];
		while (end>=0)
		{
			if (arr[end] > tem)
			{
				arr[end + 1] = arr[end];
				end--;
			}
			else
			{
				break;
			}
		}
		arr[end+1]=tem;
	}
}
void Shellsort(int* arr, int n)
{ 
	int gap = n;
	while (gap > 1)
	{
		gap = gap/3 + 1;
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int tem = arr[end + gap];
			while (end >= 0)
			{
				if (arr[end] > tem)
				{
					arr[end + gap] = arr[end];
					end-=gap;
				}
				else
				{
					break;
				}
			}
			arr[end + gap] = tem;
		}
	}
}
int main()
{
	int arr[] = {5,4,7,23,43,54,34,123,53};
	int n = sizeof(arr) / sizeof(arr[0]);
	Arrprint(arr, n);
	Shellsort(arr,n);//Insertsort(arr,n);
	Arrprint(arr, n);
	return 0;
}